import { param2Obj } from '@/utils'

const userMap = {
  gmqx: {
    roles: ['admin', 'qixiang', 'business'],
    password: 'gmqx9210',
    token: 'gmqx',
    introduction: '我是管理员',
    avatar:
      'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
    name: '高明气象'
  },
  tornado: {
    roles: ['tornado', 'qixiang'],
    password: 'tornado',
    token: 'tornado',
    introduction: '我是龙卷风用户',
    avatar:
      'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
    name: '佛山龙卷风研究中心'
  },
  guest: {
    roles: ['guest', 'qixiang'],
    password: 'guest',
    token: 'guest',
    introduction: '我是一般用户',
    avatar:
      'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
    name: 'Guest'
  }
}

export default {
  loginByUsername: config => {
    const { username } = JSON.parse(config.body)
    return userMap[username]
  },
  getUserInfo: config => {
    const { token } = param2Obj(config.url)
    if (userMap[token]) {
      return userMap[token]
    } else {
      return false
    }
  },
  logout: () => 'success'
}
